package com.wx.wxsecondskill.vo;


import com.wx.wxsecondskill.po.User;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

import static com.wx.wxsecondskill.enums.SecondsKillEnumStatus.SecondsKillForStatus.*;

@Data
public class GoodsDetailVo implements Serializable {
	private static final long serialVersionUID = 8767830866091133325L;
	/**
	 * 秒杀状态 0-未开始  1-进行中  2-已经结束
	 */
	private int secondsKillStatus = SECONDS_KILL_FOR_STATUS_0.getCode();
	/**
	 * 倒计时
	 */
	private int remainSeconds = 0;
	private GoodsVo goods;
	private User user;


	public void setGoods(GoodsVo goods) {
		this.goods = goods;
		/** Start 初始化秒杀状态与倒计时 */
		Date now = new Date();
		long startAt = goods.getStartDate().getTime();
		long endAt = goods.getEndDate().getTime();
		long nowTime = System.currentTimeMillis();
		//秒杀还没开始，倒计时
		if(nowTime < startAt ) {
			this.remainSeconds = (int)((startAt - nowTime )/1000);
		}
		//秒杀已经结束
		else  if(nowTime > endAt){
			this.secondsKillStatus = SECONDS_KILL_FOR_STATUS_2.getCode();
			this.remainSeconds = -1;
		}
		//秒杀进行中
		else {
			this.secondsKillStatus = SECONDS_KILL_FOR_STATUS_1.getCode();
		}
		/** End  */
	}


}
